<?php

namespace App\Http\Middleware;

use App\Common\BusinessCode;
use App\Exceptions\PermissionException;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Symfony\Component\HttpFoundation\Response;

class RbacCheck
{
    /**
     * Handle an incoming request.
     *
     * @param \Closure(\Illuminate\Http\Request): (Response) $next
     * @param Request                                        $request
     */
    public function handle(Request $request, Closure $next): Response
    {
        /*
         TODO 在此处添加权限校验逻辑
        $route = $request->route();
        if ($route !== null) {
            Log::warning("You don't have permission to operate this!", ['routeUrl' => $route->uri, 'routeName' => $route->getName(), 'method' => $request->method()]);
            throw new PermissionException(BusinessCode::$businessCodeMap[BusinessCode::PERMISSION_NOT_ALLOWED], BusinessCode::PERMISSION_NOT_ALLOWED);
        }
        */

        return $next($request);
    }
}
